CREATE FUNCTION months_between(TIMESTAMP, TIMESTAMP) RETURNS integer AS $$
        select (date_part('month',age($1,$2))+date_part('year',age($1,$2))*12)::INTEGER;
    $$ LANGUAGE SQL;